﻿Imports System
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports OMANE.Common.UI
Imports System.Collections.ObjectModel

Partial Public Class ViewEditableParameterSection
    Public Sub New()
        MyBase.New()

        Me.InitializeComponent()

        ' Insert code required on object creation below this point.
    End Sub
End Class
Public Class ViewModelEditableParameterSection
    Inherits ViewModelBase
    Implements IViewModelTabSection


    Dim _Params As ViewModelParametres

    Sub New(ByVal params As ViewModelParametres)
        Me._Params = params
    End Sub

    Public Property Icone As String Implements Common.UI.IViewModelTabSection.Icone

    Public Property Title As String Implements Common.UI.IViewModelTabSection.Title


    Private _Groups As New ObservableCollection(Of ViewModelEditableParameterSectionGroup)
    Public ReadOnly Property Groups As ObservableCollection(Of ViewModelEditableParameterSectionGroup)
        Get
            Return _Groups
        End Get
    End Property

    Private _AddGroupCommand As New DelegateCommand(Of Object)(AddressOf AddGroupExecute)
    Public ReadOnly Property AddGroupCommand As DelegateCommand(Of Object)
        Get
            Return _AddGroupCommand
        End Get
    End Property
    Private Sub AddGroupExecute(ByVal parameter As Object)
        Groups.Add(New ViewModelEditableParameterSectionGroup(_Params) With {.Name = InputBox("Nom du group")})
    End Sub

    Public Property IsClosable As Boolean Implements IViewModelTabSection.IsClosable
End Class

Public Class ViewModelEditableParameterSectionGroup
    Inherits ViewModelBase

    Dim _Params As ViewModelParametres

    Sub New(ByVal params As ViewModelParametres)
        Me._Params = params
    End Sub

    Property Name As String

    Protected _Paramters As New ObservableCollection(Of ViewModelEditableParameterSectionParameter)
    Public ReadOnly Property Paramters As ObservableCollection(Of ViewModelEditableParameterSectionParameter)
        Get
            Return _Paramters
        End Get
    End Property

    Private _AddParameterCommand As New DelegateCommand(Of Object)(AddressOf AddParameterExecute)
    Public ReadOnly Property AddParameterCommand As DelegateCommand(Of Object)
        Get
            Return _AddParameterCommand
        End Get
    End Property
    Private Sub AddParameterExecute(ByVal parameter As Object)
        If _Paramters Is Nothing Then
            _Paramters = New ObservableCollection(Of ViewModelEditableParameterSectionParameter)
        End If
        Paramters.Add(New ViewModelEditableParameterSectionParameter(parameter))

        Dim lst As New List(Of String)
        For Each e In Params
            lst.Add(e.Name)
        Next

    End Sub

    Public ReadOnly Property Params As ObjectModel.ObservableCollection(Of ModelParamType)
        Get
            Return _Params.Params
        End Get
    End Property
    ' 
End Class

Public Class ViewModelEditableParameterSectionParameter
    Inherits ViewModelBase

    Private _parameter As ModelParamType

    Sub New(ByVal parameter As Object)
        ' TODO: Complete member initialization 
        _parameter = parameter
    End Sub

    ReadOnly Property Title As String
        Get
            Return _parameter.Legend
        End Get
    End Property

    ReadOnly Property Parameter As ModelParamType
        Get
            Return _parameter
        End Get
    End Property
End Class

Public Class ModelParamTypeStyleSelector
    Inherits StyleSelector

    Public Overrides Function SelectStyle(ByVal item As Object, ByVal container As System.Windows.DependencyObject) As System.Windows.Style
        Return MyBase.SelectStyle(item, container)
    End Function
End Class
Public Class ModelParamTypeTemplateSelector
    Inherits DataTemplateSelector

    Public Overrides Function SelectTemplate(ByVal item As Object, ByVal container As System.Windows.DependencyObject) As System.Windows.DataTemplate
        Try
            Dim mdl As ViewModelEditableParameterSectionParameter = item
            Dim presenter As ContentPresenter = container
            Dim contentctrl As ContentControl = presenter.TemplatedParent

            Select Case mdl.Parameter.UnderlyingType
                Case ModelParamUnderLyingType.Boolean
                    Return contentctrl.Resources("Boolean")
                Case ModelParamUnderLyingType.Date
                    Return contentctrl.Resources("Date")
                Case ModelParamUnderLyingType.Double
                    Return contentctrl.Resources("Double")
                Case ModelParamUnderLyingType.Case
                    Return contentctrl.Resources("Case")
                Case ModelParamUnderLyingType.Uncertain
                    Return contentctrl.Resources("Uncertain")
                Case ModelParamUnderLyingType.Time
                    Return contentctrl.Resources("Time")
                Case ModelParamUnderLyingType.Mixed
                    Return contentctrl.Resources("Default")
            End Select

            Return contentctrl.Resources("Default")
        Catch ex As Exception
            Return MyBase.SelectTemplate(item, container)
        End Try
    End Function
End Class



Public Class CustomUniformGrid
    Inherits Primitives.UniformGrid



    Public Property Mode As CustomUniformGridMode
        Get
            Return GetValue(ModeProperty)
        End Get

        Set(ByVal value As CustomUniformGridMode)
            SetValue(ModeProperty, value)
        End Set
    End Property

    Public Shared ReadOnly ModeProperty As DependencyProperty = _
                           DependencyProperty.Register("Mode", _
                           GetType(CustomUniformGridMode), GetType(CustomUniformGrid), _
                           New FrameworkPropertyMetadata(CustomUniformGridMode.Default))

    Protected Overrides Sub OnVisualChildrenChanged(ByVal visualAdded As System.Windows.DependencyObject, ByVal visualRemoved As System.Windows.DependencyObject)
        If visualAdded IsNot Nothing Then
            Rows += 1
        End If
        If visualRemoved IsNot Nothing Then
            Rows -= 1
        End If
        MyBase.OnVisualChildrenChanged(visualAdded, visualRemoved)
    End Sub


End Class

Public Enum CustomUniformGridMode
    [Default] = 1
    Vertical = 1
    Horizontal = 2
    Both = 2
End Enum